﻿//***********************************************************************
// Assembly         : IGolovkine.AoA.Core
// Author           : Ilia
// Created          : 06-11-2011
//
// Last Modified By : Ilia
// Last Modified On : 06-11-2011
// Description      : 
//
// Copyright        : (c) Microsoft. All rights reserved.
//***********************************************************************
using System;
using IGolovkine.AoA.BinarySerialization;
using System.Globalization;

namespace IGolovkine.AoA.Tcp
{
    [Serializable]
    public class TcpConnectionInitiated : TcpConnectionMessage
    {
        private readonly string _host;
        private readonly int _port;

        public TcpConnectionInitiated(CorrelationId connectionId, string host, int port)
            : base(connectionId)
        {
            _host = host;
            _port = port;
        }

        protected TcpConnectionInitiated(ISlimBinaryReader reader)
            : base(reader)
        {
            _host = reader.ReadString();
            _port = reader.ReadInt32();
        }

        public string Host
        {
            get { return _host; }
        }

        public int Port
        {
            get { return _port; }
        }

        public override void Serialize(ISlimBinaryWriter writer)
        {
            base.Serialize(writer);
            writer.WriteString(_host);
            writer.WriteInt32(_port);
        }

        public override string ToString()
        {
            return string.Format(CultureInfo.CurrentCulture, "{0}: Host = {1}:{2}", this.GetType().Name, _host, _port);
        }
    }
}
